import { createSelector } from '@ngrx/store';

import { MapState } from '../reducers';
import { getMapState } from './map.selector';
import { PoisState } from '../reducers/pois.reducer';
import { Poi } from '../../../ngx-ol/models';

const getPoisState = createSelector(getMapState, (state: MapState) => state.pois);
const getPoisEntities = createSelector(getPoisState, (state: PoisState) => state.entities);
const getAllPois = createSelector(getPoisEntities, (entities: { [id: string]: Poi }) => {
    return Object.keys(entities).map(id => entities[id]);
});
const getSelectPois = createSelector(getPoisState, (state: PoisState) => state.selected);
const getPoisLoaded = createSelector(getPoisState, (state: PoisState) => state.loaded);
const getPoisLoading = createSelector(getPoisState, (state: PoisState) => state.loading);
const getPoisKeywords = createSelector(getPoisState, (state: PoisState) => state.keywords);

export const poisSelectors = {
    getPoisState,
    getPoisEntities,
    getAllPois,
    getSelectPois,
    getPoisLoaded,
    getPoisLoading,
    getPoisKeywords
};